﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DHQGHN.DAL.Models.Admin;
namespace DHQGHN.PM0.Models.Admin
{
    public class RelationModel
    {
        public string RELATION_ID { get; set; }

        [Remote("CheckExistRelationName", "Relation", ErrorMessage = "RelationNameExist", HttpMethod = "POST", AdditionalFields = "RELATION_ID")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập tên mối quan hệ")]
        [StringLength(255, ErrorMessage = "Độ dài tối đa là 255 ký tự")]
        [Display(Name = "Tên mối quan hệ")]
        public string NAME { get; set; }

        [Remote("CheckExistRelationCode", "Relation", ErrorMessage = "RelationCodeExist", HttpMethod = "POST", AdditionalFields = "RELATION_ID")]
        [Required(AllowEmptyStrings = false, ErrorMessage = "Bạn chưa nhập mã mối quan hệ")]
        [Display(Name = "Mã mối quan hệ ")]
        [StringLength(12, ErrorMessage = "Độ dài tối đa là 12 ký tự")]
        [RegularExpression(@"^[a-zA-Z0-9]+[a-zA-Z0-9_]*[a-zA-Z0-9]*$", ErrorMessage = "Mã không đúng định dạng")]
        public string CODE { get; set; }

        [Display(Name = "Mô tả")]
        [StringLength(255, ErrorMessage = "Độ dài tối đa là 255 ký tự")]
        public string DESCRIPTIONS { get; set; }
        public int DELETED { get; set; }
        public int RecordCount { get; set; }
        //dua ra cac truongco trong bang 
        #region
        public const string FIELD_RELATION_ID = "RELATION_ID";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        public const string FIELD_RECORD_COUNT = "RecordCount";
        #endregion

        public RelationModel()
        {
            // TODO: Complete member initialization
        }

        public RelationModel(DAL.Models.Admin.RelationModel model)
        {
            // TODO: Complete member initialization
            RELATION_ID = model.RELATION_ID;
            CODE = model.CODE;
            NAME = model.NAME;
            DESCRIPTIONS = model.DESCRIPTIONS;
            RecordCount = model.RecordCount;
            DELETED  = model.DELETED;
    
        }


        internal DAL.Models.Admin.RelationModel toDALModel()
        {
            DAL.Models.Admin.RelationModel model = new DAL.Models.Admin.RelationModel
            {
                RELATION_ID = RELATION_ID,
                CODE = CODE,
                NAME = NAME,
                DESCRIPTIONS = DESCRIPTIONS,
                RecordCount = RecordCount,
                DELETED =DELETED
            };
            return model;
        }
    }
}